package com.food.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class AppConfig implements WebMvcConfigurer {

    ///配置跨域请求
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        //添加映射
        registry.addMapping("/**")
                //允许所有来源
                .allowedOriginPatterns("*")
                //允许的请求方法
                .allowedMethods("GET","POST","PUT","DELETE","OPTIONS")
                //允许的请求头
                .allowedHeaders("*")
                .maxAge(3600)
                //允许发送Cookie
                .allowCredentials(true);
    }
    //配置静态资源访问
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/images2/**")
                //文件放在本地的路径下
                .addResourceLocations("file:F:/images2/");
    }

}
